Displaying a List of Nonworking Devices
Device Manager’s
icons (discussed in the previous section) are great, but it’s not always
convenient to fire up Device Manager to check for problems. To avoid
that, use the script in Listing 1, which displays a list of all the problem devices on your system.
Listing 1. Script That Displays a List of a PC’s Nonworking Devices
Option Explicit Dim strComputer, objWMI, collDevices, objDevice Dim intDevices, strMessage ' ' Get the WMI object ' strComputer = "." Set objWMI = GetObject("winmgmts:\\" & _ strComputer & "\root\cimv2") ' ' Return the collection of nonworking devices on the computer ' Set collDevices = objWMI.ExecQuery _ ("Select * from Win32_PnPEntity " _ & "WHERE ConfigManagerErrorCode <> 0") ' ' Run through each item in the collection ' intDevices = 0 strMessage = "" For Each objDevice in collDevices strMessage = strMessage & "Device Name: " & objDevice.Name & vbCrLf strMessage = strMessage & "Manufacturer: " & objDevice.Manufacturer & vbCrLf strMessage = strMessage & "Device ID: " & objDevice.DeviceID & vbCrLf strMessage = strMessage & "Service: " & objDevice.Service & vbCrLf strMessage = strMessage & "Error Code: " & objDevice.ConfigManagerErrorCode & vbCrLf strMessage = strMessage & vbCrLf & vbCrLf intDevices = intDevices + 1 Next ' ' Display the results ' If intDevices = 0 Then WScript.Echo "No non-working devices found!" Else WScript.Echo "Found " & intDevices & " non-working device(s):" & _ vbCrLf & vbCrLf & _ strMessage End If
|
The script sets up the WMI object and then uses WMI to return the collection of nonworking devices (that is, where the device’s ConfigManagerErrorCode property isn’t 0). A For Each...Next
loop goes through each device and stores various data about the device
to a string variable, including the device name and ID, and the error
code. The script then displays the results, and Figure 3 shows an example.
Table 1 lists the various error codes and what they mean.
Table 1. Error Codes for Nonworking Devices
Code | Description |
---|
0 | Device is working properly. |
1 | Device is not configured correctly. |
2 | Windows cannot load the driver for this device. |
3 | Driver for this device might be corrupted, or the system may be low on memory or other resources. |
4 | Device is not working properly. One of its drivers or the Registry might be corrupted. |
5 | Driver for the device requires a resource that Windows cannot manage. |
6 | Boot configuration for the device conflicts with other devices. |
7 | Cannot filter. |
8 | Driver loader for the device is missing. |
9 | Device is not working properly. The controlling firmware is incorrectly reporting the resources for the device. |
10 | Device cannot start. |
11 | Device failed. |
12 | Device cannot find enough free resources to use. |
13 | Windows cannot verify the device’s resources. |
14 | Device cannot work properly until the computer is restarted. |
15 | Device is not working properly because of a possible reenumeration problem. |
16 | Windows cannot identify all the resources that the device uses. |
17 | Device is requesting an unknown resource type. |
18 | Device drivers must be reinstalled. |
19 | Failure using the Vloader. |
20 | Registry might be corrupted. |
21 | System failure. If changing the device driver is ineffective, see the hardware documentation. Windows is removing the device. |
22 | Device is disabled. |
23 | System failure. If changing the device driver is ineffective, see the hardware documentation. |
24 | Device is not present, not working properly, or does not have all its drivers installed. |
25 | Windows is still setting up the device, but the installation is incomplete. |
26 | Windows
is still setting up the device, but not all the devices drivers were
installed or there’s a problem with one of the device drivers. |
27 | Device does not have valid log configuration. |
28 | Device drivers are not installed. |
29 | Device is disabled. The device firmware did not provide the required resources. |
30 | Device is using an IRQ resource that another device is using. |
31 | Device is not working properly. Windows cannot load the required device drivers. |